package com.spring.boot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.spring.boot.entity.ProvinceCity;
import com.spring.boot.mapper.CityMapper;
import com.spring.boot.mapper.ProvinceMapper;
import com.spring.boot.service.ProvinceMapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
public class ProvinceMapServiceImpl implements ProvinceMapService {

    @Autowired
    private ProvinceMapper provinceMapper;
    @Autowired
    private CityMapper cityMapper;

    @Override
    public List<Integer> getProvinceMapData(String date) {
        if (date.equals("")){
            List<Integer> curConfirmList = Arrays.asList(new Integer[9]);
            QueryWrapper<ProvinceCity> provinceQueryWrapper = new QueryWrapper<>();
            provinceQueryWrapper.orderByDesc("create_time").last("limit 9");
            List<ProvinceCity> cityList = cityMapper.selectList(provinceQueryWrapper);
            for (ProvinceCity city : cityList) {
                String curConfirm = city.getCurConfirm();//现有确诊
                String cityName = city.getCity();
                switch (cityName){
                    case ("福州"):
                        curConfirmList.set(0,Integer.valueOf(curConfirm));
                        break;
                    case ("厦门"):
                        curConfirmList.set(1,Integer.valueOf(curConfirm));
                        break;
                    case ("漳州"):
                        curConfirmList.set(2,Integer.valueOf(curConfirm));
                        break;
                    case ("泉州"):
                        curConfirmList.set(3,Integer.valueOf(curConfirm));
                        break;
                    case ("三明"):
                        curConfirmList.set(4,Integer.valueOf(curConfirm));
                        break;
                    case ("莆田"):
                        curConfirmList.set(5,Integer.valueOf(curConfirm));
                        break;
                    case ("南平"):
                        curConfirmList.set(6,Integer.valueOf(curConfirm));
                        break;
                    case ("龙岩"):
                        curConfirmList.set(7,Integer.valueOf(curConfirm));
                        break;
                    case ("宁德"):
                        curConfirmList.set(8,Integer.valueOf(curConfirm));
                        break;
                }
            }
            return curConfirmList;
        }
        else {
            List<Integer> curConfirmList = Arrays.asList(new Integer[9]);
            QueryWrapper<ProvinceCity> provinceQueryWrapper = new QueryWrapper<>();
            provinceQueryWrapper.eq("create_time",date).orderByDesc("create_time").last("limit 11");
            List<ProvinceCity> cityList = cityMapper.selectList(provinceQueryWrapper);
            for (ProvinceCity city : cityList) {
                String curConfirm = city.getCurConfirm();//现有确诊
                String cityName = city.getCity();
                switch (cityName){
                    case ("福州"):
                        curConfirmList.set(0,Integer.valueOf(curConfirm));
                        break;
                    case ("厦门"):
                        curConfirmList.set(1,Integer.valueOf(curConfirm));
                        break;
                    case ("漳州"):
                        curConfirmList.set(2,Integer.valueOf(curConfirm));
                        break;
                    case ("泉州"):
                        curConfirmList.set(3,Integer.valueOf(curConfirm));
                        break;
                    case ("三明"):
                        curConfirmList.set(4,Integer.valueOf(curConfirm));
                        break;
                    case ("莆田"):
                        curConfirmList.set(5,Integer.valueOf(curConfirm));
                        break;
                    case ("南平"):
                        curConfirmList.set(6,Integer.valueOf(curConfirm));
                        break;
                    case ("龙岩"):
                        curConfirmList.set(7,Integer.valueOf(curConfirm));
                        break;
                    case ("宁德"):
                        curConfirmList.set(8,Integer.valueOf(curConfirm));
                        break;
                }
            }
            return curConfirmList;
        }

    }
}
